package cn.dglydrpy.study.j2ee.jdbc;

import java.sql.Connection;

import cn.dglydrpy.study.j2ee.jdbc.utils.DBUtil;

/**
 * 验证多线程下超过最大线程数时  获取连接 等待的效果
 * @author hasee
 *
 */
public class GetConnWaitDemo {
	
	public static void main(String[] args) {
		DemoThread t1 = new DemoThread();
		t1.start();
		DemoThread t2 = new DemoThread();
		t2.start();
		DemoThread t3 = new DemoThread();
		t3.start();
		DemoThread t4 = new DemoThread();
		t4.start();		
		DemoThread t5 = new DemoThread();
		t5.start();		
		DemoThread t6 = new DemoThread();
		t6.start();		
	}
}

class DemoThread extends Thread{
	@Override
	public void run() {
		try {
			Connection conn = DBUtil.getConn();
			System.out.println(Thread.currentThread().getName()+"得到连接");
			Thread.sleep(5*1000);//睡眠五秒
			conn.close();
			System.out.println(Thread.currentThread().getName()+"归还连接");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
